<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of video_m
 *
 * @author Gidaff_01
 */
class video_m extends Model{
    //put your code here
    function Video_m(){
          parent::Model();
          $this->load->database();
    }

    function upload_video($data){
       is_admin();
       $query = $this->db->insert('seating_videos', $data);
       return $query;
    }

    function get_all_video($per_page,$off_set){
        $this->db->select('lehu_profiles.display_name,seating_videos.id,seating_videos.name,
            seating_videos.description,seating_videos.file_name,
            seating_videos.upload_time,seating_videos.upload_by');
        $this->db->from('seating_videos,lehu_users,lehu_profiles');
        $this->db->where('seating_videos.upload_by = lehu_users.id ');
        $this->db->where('lehu_users.id = lehu_profiles.user_id');
        $this->db->order_by('seating_videos.id', 'DESC');
        $this->db->limit($per_page,$off_set);
        $query = $this->db->get();
        return $query->result_array();
    }

    function delete_video($id){
        return $this->db->delete('seating_videos', array('id' => $id));
    }

    function delete_video_comment($id){
        return $this->db->delete('seating_video_comment', array('video_id' => $id));
    }

    function get_video_by_id($id){
        $this->db->select('lehu_profiles.display_name,seating_videos.id,seating_videos.name,
            seating_videos.description,seating_videos.file_name,
            seating_videos.upload_time,seating_videos.upload_by');
        $this->db->from('seating_videos,lehu_users,lehu_profiles');
        $this->db->where('seating_videos.upload_by = lehu_users.id ');
        $this->db->where('lehu_users.id = lehu_profiles.user_id');
        $this->db->where('seating_videos.id',$id);
        $query = $this->db->get();
        return $query;
    }

    function count_video_by_id($id){
        $this->db->select('lehu_profiles.display_name,seating_videos.id,seating_videos.name,
            seating_videos.description,seating_videos.file_name,
            seating_videos.upload_time,seating_videos.upload_by');
        $this->db->from('seating_videos,lehu_users,lehu_profiles');
        $this->db->where('seating_videos.upload_by = lehu_users.id ');
        $this->db->where('lehu_users.id = lehu_profiles.user_id');
        $this->db->where('seating_videos.id',$id);
        $query = $this->db->get();
        return count($query->result_array());
    }

    function edit_video($data,$id){
        return $this->db->update('seating_videos', $data, array('id' => $id));
    }
}
?>
